﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;

namespace Server_NhaSach.DataAccess.LogicLayer
{
    [Serializable]
    public class PhieuKHDatHangDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion

        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion

        #region "Khai báo các Method"
        public bool InsertPhieuKHDatHang(PhieuKHDatHangDTO PhieuKHDatHang)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[12];
            par[0] = new SqlParameter("@MAKHDH", PhieuKHDatHang.Makhdh);
            par[1] = new SqlParameter("@MaKho", PhieuKHDatHang.Makho);
            par[2] = new SqlParameter("@MaKh", PhieuKHDatHang.Makh);
            par[3] = new SqlParameter("@MaNV", PhieuKHDatHang.Manv);
            par[4] = new SqlParameter("@SoChungTuDH", PhieuKHDatHang.Sochungtudh);
            par[5] = new SqlParameter("@NgayThangDH", PhieuKHDatHang.Ngaythangdh);
            par[6] = new SqlParameter("@DiaChi", PhieuKHDatHang.Diachi);
            par[7] = new SqlParameter("@GhiChuDH", PhieuKHDatHang.Ghichu);
            par[8] = new SqlParameter("@TongTien", PhieuKHDatHang.Tongtien);
            par[9] = new SqlParameter("@TamUng", PhieuKHDatHang.Tamung);
            par[10] = new SqlParameter("@ConLai", PhieuKHDatHang.Conlai);
            par[11] = new SqlParameter("@NgayBanGiao", PhieuKHDatHang.Ngaybangiao);
            try
            {
                helper.InsertQuery("sp_Insert_PhieuKHDatHang", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdatePhieuKHDatHang(PhieuKHDatHangDTO PhieuKHDatHang)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[12];
            par[0] = new SqlParameter("@MAKHDH", PhieuKHDatHang.Makhdh);
            par[1] = new SqlParameter("@MaKho", PhieuKHDatHang.Makho);
            par[2] = new SqlParameter("@MaKh", PhieuKHDatHang.Makh);
            par[3] = new SqlParameter("@MaNV", PhieuKHDatHang.Manv);
            par[4] = new SqlParameter("@SoChungTuDH", PhieuKHDatHang.Sochungtudh);
            par[5] = new SqlParameter("@NgayThangDH", PhieuKHDatHang.Ngaythangdh);
            par[6] = new SqlParameter("@DiaChi", PhieuKHDatHang.Diachi);
            par[7] = new SqlParameter("@GhiChuDH", PhieuKHDatHang.Ghichu);
            par[8] = new SqlParameter("@TongTien", PhieuKHDatHang.Tongtien);
            par[9] = new SqlParameter("@TamUng", PhieuKHDatHang.Tamung);
            par[10] = new SqlParameter("@ConLai", PhieuKHDatHang.Conlai);
            par[11] = new SqlParameter("@NgayBanGiao", PhieuKHDatHang.Ngaybangiao);
            try
            {
                helper.UpdateQuery("sp_Update_PhieuKHDatHang", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeletePhieuKHDatHang(string maKHDH)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@maKHDH", maKHDH);
            try
            {
                helper.DeleteQuery("sp_Delete_PhieuKHDatHang", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_PhieuKHDatHang()
        {
            helper = new Helper();
            DataSet ds = helper.SelectQuery("sp_LayDS_PhieuKHDatHang");
            return ds;
        }
        #endregion
    }
}